package com.lfg.message.delay.message.demo.delay.redis;

import org.redisson.api.RBlockingQueue;
import org.redisson.api.RedissonClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * @author lfg
 * @version v1.0
 */
@Component
@EnableScheduling
public class Consumer3 {

    private static final Logger log = LoggerFactory.getLogger(Consumer3.class);

    @Autowired
    private RedissonClient redissonClient;

    @Scheduled(fixedDelay = 1000)
    public void consume() throws InterruptedException {
        RBlockingQueue<String> queue = redissonClient.getBlockingQueue("redis-key-name");
        String message = queue.take();
        log.info("正在消费推送信息：" + message);
        //此种方式抛异常也会正常消费掉消息
    }
}
